package com.man.control;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.man.daoService.DaoService;
import com.man.entity.User;

public class UserManage {
	private DaoService daoService=new DaoService();
	public void select() throws IOException
	{	
		User user=(User) ServletActionContext.getRequest().getSession().getAttribute("user");
		User user2=	daoService.oneUserInformation(user);
		
		JSONObject jsonObject=JSONObject.fromObject(user2);
		ServletActionContext.getResponse().setCharacterEncoding("utf-8");
		ServletActionContext.getResponse().getWriter().print(jsonObject);
	}
	public void updata()
	{
		User user=(User) ServletActionContext.getRequest().getSession().getAttribute("user");
		User user2=new User();
		user2.setUserName(user.getUserName());
		user2.setName(getName());
		user2.setBirth(getBirth());
		user2.setEdu(getEdu());
		user2.setEmail(getEmail());
		user2.setNation(getNation());
		user2.setPhone(getPhone());
		user2.setPlace(getPlace());
		user2.setSex(getSex());
		user2.setWork(getWork());
		Boolean b=	daoService.oneUserUpdata(user2);
		ServletActionContext.getResponse().setCharacterEncoding("utf-8");
		try {
			ServletActionContext.getResponse().getWriter().print(b);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
	public void updataPassword()
	{
		User user=(User) ServletActionContext.getRequest().getSession().getAttribute("user");
		User user2=new User();
		user2.setUserName(user.getUserName());
		user2.setPassword(getPassword());
		Boolean b=	daoService.passwordUserUpdata(user2);
		ServletActionContext.getResponse().setCharacterEncoding("utf-8");
		try {
			ServletActionContext.getResponse().getWriter().print(b);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
	private String userName;  //登录名
	private String password;//登录密码
	private String name;//真实姓名
	private String sex;//用户性别
	private String birth;//出生日期
	private String nation;//用户民族
	private String edu;//用户学历
	private String work;//用户职称
	private String phone;//用户电话
	private String place;//用户住址
	private String email;//用户邮箱
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getBirth() {
		return birth;
	}
	public void setBirth(String birth) {
		this.birth = birth;
	}
	public String getNation() {
		return nation;
	}
	public void setNation(String nation) {
		this.nation = nation;
	}
	public String getEdu() {
		return edu;
	}
	public void setEdu(String edu) {
		this.edu = edu;
	}
	public String getWork() {
		return work;
	}
	public void setWork(String work) {
		this.work = work;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getPlace() {
		return place;
	}
	public void setPlace(String place) {
		this.place = place;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}

}
